#ifndef __LOG_4_C_H__
#define __LOG_4_C_H__

#include <stdlib.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SG_LOG_CR "\n"

/**
 * @Description  :  write log with fprintf()
 */
#define sg_log4c_write(log , log_level , msg) do {\
	if (log->level >= log_level) {\
		fprintf(log->file,"[%s:%u][%s] %s\n",__FILE__,__LINE__,log_level==SG_ERROR?"err":"ok",msg);\
	}\
}while(0)\

typedef enum _log_level
{
	SG_ERROR = 0, /*WARNING,*/ SG_DEBUG, SG_TRACE, SG_ALL
}sg_log_level;

typedef struct __log_t
{
	unsigned int level; /* level of log to record : ERROR , WARNING , DBUG , ALL */
	FILE* file; /* output file */
} sg_log_t;

/**
 * @Params : filepath , which file to be written . if NULL "stdout" will be set
 * 				     level , ERROR & WARNING & DEBUG & ALL
 * @Return  : pointer to the log_t structure . if failed , it's NULL
 */
sg_log_t* sg_log4c_init(const char* filepath , sg_log_level level);

/**
 * @Params  :  log_t* to be destroyed
 */
void sg_log4c_destroy(sg_log_t* log);


#ifdef __cplusplus
}
#endif


#endif
